#include <vector>
#include <iostream>
#include <cassert>

using namespace std;

template <class T>
class Less
{
public:
	bool operator()(const T& x, const T& y)
	{
		return x < y;
	}
};

template <class T>
class Greater
{
public:
	bool operator()(const T& x, const T& y)
	{
		return x > y;
	}
};

template <class T, class Container = vector<T>, class Compare = Less<T>>
class priority_queue
{
public:
	priority_queue() {}
	priority_queue(const Container &con) 
	{
		for (auto& item : con)
		{
			push(item);
		}
	}

	void push(T data)
	{
		_con.push_back(data);
		adjustUp();
	}

	T pop()
	{
		T data = _con.front();
		swap(_con[0], _con[_con.size() - 1]);
		_con.pop_back();
		adjustDown();
		return data;
	}

	T top() { return _con.front(); }
	size_t size() { return _con.size(); }
	bool empty() { return _con.empty(); }

private:
	void adjustUp()
	{
		int child = _con.size() - 1;
		int parent = (child - 1) / 2;
		while (parent >= 0)
		{
			if (com(_con[parent], _con[child]))
			{
				swap(_con[parent], _con[child]);
				child = parent;
				parent = (child - 1) / 2;
			}
			else break;
		}
	}

	void adjustDown()
	{
		int parent = 0;
		int child = 1;
		while (child < size())
		{
			if (child + 1 < size())
			{
				if (com(_con[child], _con[child + 1]))
				{
					child = child + 1;
				}
			}
			if (com(_con[parent], _con[child]))
			{
				swap(_con[parent], _con[child]);
				parent = child;
				child = parent * 2 + 1;
			}
			else break;
		}
	}

private:
	Container _con;
	Compare com;
};